package com.clgc.baseservice.handler;

import com.clgc.baseservice.exception.MyException;
import com.clgc.utils.R;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author lsr
 * @create 2021-04-17-16:04
 */
@ControllerAdvice
@ResponseBody
public class MyExceptionHandler {

    @ExceptionHandler(MyException.class)
    public R MyExceptionHandle(MyException e){

        return R.error().message(e.getMsg()).code(e.getCode());
    }

    @ExceptionHandler(Exception.class)
    public R ExceptionHandle(Exception e){
        e.printStackTrace();
        return R.error().message("全局异常处理").data("ExceptionType",e);
    }

}
